package Year21_Month10.day1017_2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

//关于遍历
public class Test_3 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>(10);
        for (int i = 1; i < 6; i++) {
            list.add(i);
        }

        //遍历方式一：for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+ " " );
        }
        System.out.println();
        //方式二：for -each循环
        for(Integer i : list){
            System.out.print(i + " ");
        }
        System.out.println();
        //方式三：迭代器
        Iterator<Integer> it = list.listIterator();
        while (it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
    }
}
